﻿#pragma once
#include<SFML/Graphics.hpp>
#include <vector>
#include "../../libcat/include/util/json.h"
#include "../../libcat/include/cat-interaction.hpp"
class keyboard {
	struct key_save {
		std::vector<int> keys;
		bool isShow = false;
		bool isLastShow = false;
		unsigned int LastShowCount = 0;
		sf::Time record;
	};
public:
	static keyboard* GetInstance();

	static void ReleaseInstance();

	void Init(Json::Value cfg);

	void Update(Json::Value cfg);

	void Draw(void* _window);

	void Release();

	void OnKeyPress(const int vk, bool key_up);

protected:
	keyboard();

	~keyboard();

private:
	void drawCat(sf::RenderTexture& _window);
	void drawKey(sf::RenderTexture& _window);
	void drawLeftHand(sf::RenderTexture& _window);
	void drawRightHand(sf::RenderTexture& _window);
	void drawFace(sf::RenderTexture& _window);
	void playSound();
	void playMotion();
	void playExpression();

	bool isInit;

	int windowWidth, windowHeight;
	int horizontal, vertical;

	sf::Sprite bg,cat, left_up, right_up;

	float l2d_correct,l2d_offset_x,l2d_offset_y;
	bool l2d_random_motion, l2d_random_expression;

	int renderWindowWidth, renderWindowHeight;
	sf::RenderTexture renderTexture;
	sf::Sprite renderSprite;

	//live2d
	bool isLive2d;
	bool is_emoticonkeep;
	bool is_soundkeep ;

	sf::Clock key_clock;				//用来判断按键先后的计时器

	std::map<int, bool> states;

	std::map<std::string, key_save> left_hands_down;
	std::map<std::string, key_save> right_hands_down;
	std::map<std::string, key_save> keys;
	std::map<std::string, key_save> faces;
	std::map<std::string, key_save> sounds;
	std::map<std::string, key_save> motions;
	std::map<std::string, key_save> expression;
};



